﻿using Exiled.API.Enums;
using Exiled.API.Features;
using Exiled.Events.EventArgs.Interfaces;
using RgCore.Database;
using RgCore.Modules;
using System;

namespace TaskSystem
{
    public sealed class TaskPlugin : RgPlugin
    {
        public override string Name => "任务系统";

        public override string Id => "Task";

        public override PluginPriority Priority => PluginPriority.Lowest;

        public override void OnDisabled()
        {
            if (DatabaseController.DatabaseDisabled)
            {
                return;
            }
            base.OnDisabled();
            TaskHandler.SetEnabled(false);
        }

        public override void OnEnabled()
        {
            if (DatabaseController.DatabaseDisabled)
            {
                Log.Warn("由于数据库未启用，此插件不加载");
                return;
            }
            base.OnEnabled();
            TaskHandler.SetEnabled(true);
        }
    }

    public struct Task
    {
        public Task(string id, string name, string description, int points_Reward, int exp_Reward, bool IsWeekly, uint target, Func<IExiledEvent, Player, bool> checker)
        {
            Id = id;
            Name = name;
            Description = description;
            Points_Reward = points_Reward;
            Exp_Reward = exp_Reward;
            this.IsWeekly = IsWeekly;
            Checker = checker;
            Target = target;
            Process = 0;
        }

        /// <summary>
        /// ID请注意与字段名保持一致
        /// </summary>
        public readonly string Id;

        public readonly string Name;
        public readonly string Description;
        public readonly int Points_Reward;
        public readonly int Exp_Reward;
        public readonly bool IsWeekly;
        public readonly uint Target;
        public uint Process;
        public bool IsCompleted => Process >= Target;
        public readonly Func<IExiledEvent, Player, bool> Checker;
    }

    [AttributeUsage(AttributeTargets.Field, AllowMultiple = true)]
    public class EventSubscriberAttribute : Attribute
    {
        public EventSubscriberAttribute(params string[] argname)
        {
            ArgName = argname;
        }

        public string[] ArgName { get; }
    }
}